<template>
	<view class="middle">
		<view style="padding-top: 20rpx;">评论图片:</view>
		<view style="padding-top: 20rpx;">
			<u-upload :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="9">
			</u-upload>
		</view>

		<!-- <view class="navInput">
			<input v-model="contact" type="​number" placeholder="请填写手机号">
		</view> -->

		<view class="rateAll">
			<view>
				<text>描述评论:</text>
				<u-rate :count="count" v-model="value"></u-rate>
			</view>
		</view>

		<view class="navInput">
			<view style="padding-top: 20rpx;">评论内容:</view>
			<u--textarea v-model="content" placeholder="请输入内容"></u--textarea>
		</view>

		<view class="middleLogo">
			<view class="middle_Btn">
				<text class="middle_Btn_one" @click="lijipingjiaApi">立即评价</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList2: [],
				fileList_new5: [],
				content: '',
				contact: '',

				count: 5,
				value: 0,
				order_code: '',
				user_id: '',
				serve_score: '',
				is_anonymous: 0,
				baseUrl:''
			}
		},
		onLoad(option) {
			this.baseUrl=this.https
			console.log(option, "////")
			this.token = uni.getStorageSync('token')
			this.order_code = option.order_code
			this.user_id = option.user_id
		},
		onShow() {

		},
		methods: {
			// 评价  
			lijipingjiaApi() {
				let image = []
				this.fileList_new5.forEach((item) => {
					image.push(item.url)
				})
				this.post('/api/qunvxckt/lijipingjia', {
					user_id: this.user_id,
					order_code: this.order_code,
					evaluate_images: image,
					serve_score: this.value,
					is_anonymous: this.is_anonymous
				}).then(data => {
					if (res.code == 1) {
						uni.showToast({
							title: '评价成功',
							duration: 1500,
							icon: 'none'
						});
						setTimeout(()=>{
							uni.switchTab({
								url: `/pages/Order/Order`
							});
						},500)
					}

				});
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
				this.fileList_new5.splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.baseUrl+'/api/common/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						header: {
							"Content-Type": "application/form-data",
							'token': this.token
						},
						success: (res) => {
							let a = res.data
							let b = JSON.parse(a)
							this.fileList_new5.push({
								url: b.data.fullurl
							})
							console.log(this.fileList_new5)
							setTimeout(() => {
								resolve(res.data)
							}, 1000)
						}
					});
				})
			},

			feedbackApi() {
				let image = []
				this.fileList_new5.forEach((item) => {
					image.push(item.url)
				})
				if (this.fileList_new5 == '') {
					uni.$u.toast('请选择图片')
				} else if (this.contact == '') {
					uni.$u.toast('请填写手机号')
				} else if (this.content == '') {
					uni.$u.toast('请填写反馈内容')
				} else {
					// this.$api.feedback({
					// 	image: image,
					// 	contact: this.contact,
					// 	content: this.content,
					// }).then((res) => {
					// 	if (res.code == 1) {
					// 		uni.$u.toast(res.message)
					// 		setTimeout(() => {
					// 			uni.navigateBack({
					// 				delta: 1,
					// 				success: () => {
					// 					// 返回成功后的回调函数
					// 				},
					// 				fail: () => {
					// 					// 返回失败后的回调函数
					// 				}
					// 			});
					// 		}, 500)
					// 	}
					// })
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #fff;
	}

	.rateAll {
		view {
			display: flex;
			margin-top: 20rpx;

			text {
				margin-right: 20rpx;
			}
		}
	}

	.navInput {
		// border-bottom: 2rpx solid #F4F4F7;
		padding: 58rpx 0 32rpx 0;

		input {
			font-size: 30rpx;
			color: #333;
			padding: 0 20rpx;
		}
	}

	.middle {
		height: 100vh;
		padding: 0 40rpx;
		box-sizing: border-box;
		background-color: #fff;


		.middleLogo {
			.middle_Btn {
				margin-top: 250rpx;

				.middle_Btn_one {
					display: block;
					width: 630rpx;
					height: 92rpx;
					line-height: 92rpx;
					background: #FF2A43;
					border-radius: 46rpx;
					margin: auto;
					font-size: 30rpx;
					font-weight: bold;
					color: #FFFFFF;
					text-align: center;
				}
			}
		}
	}
</style>